home *** CD-ROM | disk | FTP | other *** search
- //─────────────────────────────────────────────────────────────────────────────
- // BOXES.C
- //
- // A short & simple demonstation of how to include BOX.H in your programs to
- // easily access the line drawing characters.
- //
- // Written in Turbo C++ by Steve Raeburn
- // Contact me on CIX as sraeburn or Compuserve as 100015,3620
- //
- //─────────────────────────────────────────────────────────────────────────────
-
- #include <stdio.h>
- #include <conio.h>
- #include <dos.h>
- #include "box.h"
-
- char far *vid_mem;
-
- void init_video();
- void shade(int, int, int, int, char);
- void rectangle(int, int, int, int, char, char);
- void border(int, int, int, int, int, char);
- void write_char(int, int, char);
- void write_attrib(int, int, char);
- void fill_screen();
-
-
- void init_video()
- {
- union REGS r;
-
-
- r.h.ah = 0x00; // Set Video Mode
- r.h.al = 0x03; // 80 x 25 16 colour text mode;
- int86(0x10, &r, &r);
-
- vid_mem = (char far *) 0xb8000000;
- }
-
- void shade(int startx, int starty, int endx, int endy, char attrib)
- {
- register int x, y;
-
- for(y=starty; y<endy+1; y++)
- for(x=startx; x<endx+1; x++)
- write_attrib(x, y, attrib);
- }
-
- void rectangle(int startx, int starty, int endx, int endy,
- char attrib, char ch)
- {
- register int x, y;
-
- for(y=starty; y<endy+1; y++)
- for(x=startx; x<endx+1; x++)
- {
- write_char(x, y, ch);
- write_attrib(x, y, attrib);
- }
- }
-
- void border(int startx, int starty, int endx, int endy, int type, char color)
- {
- register int i;
-
- for(i=startx+1; i<endx; i++)
- {
- write_char(i, starty, box[type][1]);
- write_attrib(i, starty, color);
- write_char(i, endy, box[type][1]);
- write_attrib(i, endy, color);
- }
- for(i=starty+1; i<endy; i++)
- {
- write_char(startx, i, box[type][4]);
- write_attrib(startx, i, color);
- write_char(endx, i, box[type][4]);
- write_attrib(endx, i, color);
- }
- write_char(startx, starty, box[type][0]);
- write_attrib(startx, starty, color);
- write_char(startx, endy , box[type][8]);
- write_attrib(startx, endy, color);
- write_char(endx, starty, box[type][3]);
- write_attrib(endx, starty, color);
- write_char(endx , endy , box[type][10]);
- write_attrib(endx, endy, color);
- }
-
- void write_char(int x, int y, char ch)
- {
- register int i;
- char far *v;
-
- v = vid_mem;
- v += (x-1)*2 + ((y-1)*160);
- *v = ch;
- }
-
- void write_attrib(int x, int y, char attrib)
- {
- register int i;
- char far *v;
-
- v = vid_mem;
- v += (x-1)*2 + ((y-1)*160) + 1;
- *v = attrib;
- }
-
- void fill_screen()
- {
- register int x, y;
-
- y=0;
- for(x=0; x<41; x++)
- {
- if(x%3==0) y++;
- rectangle(40-x, 12-y, 40+x, 12+y, BLACK, 219);
- }
- }
-
- void main()
- {
- int n;
-
- init_video();
- clrscr();
- rectangle(1, 1, 80, 25, 0x71, 176);
- rectangle(2, 2, 79, 6, 0x1f, 32);
- border(2, 2, 79, 6, 2, 0x17);
- rectangle(1, 25, 80, 25, 0x0f, 32);
- gotoxy(37, 2);
- textcolor(WHITE);
- textbackground(BLUE);
- cprintf("BOXES");
- gotoxy(5, 4);
- cprintf("A demonstration of BOX.H - Used to create boxes & line draw characters");
- gotoxy(1, 25);
- textcolor(WHITE);
- textbackground(BLACK);
- for(n=0; n<5; n++)
- {
- shade((n*16)+3, 11, (n*16)+14, 16, DARKGRAY);
- rectangle((n*16)+2, 10, (n*16)+13, 15, (n+1)*16+7, 32);
- border((n*16)+2, 10, (n*16)+13, 15, n, (n+1)*16+15);
- cprintf("Box type %d%c", n, 0x07);
- gotoxy(1,25);
- sleep(2);
- }
- cprintf("This program written by Steve Raeburn :CIX sraeburn COMPUSERVE 100015,3620");
- gotoxy(1,25);
- shade(3, 19, 79, 23, DARKGRAY);
- rectangle(2, 18, 78, 22, 0x7f, 32);
- border(2, 18, 78, 22, 4, 0x71);
- textcolor(LIGHTBLUE);
- textbackground(LIGHTGRAY);
- gotoxy(8, 20);
- cprintf("All borders shown were created with the same routine using BOX.H");
- gotoxy(80,25);
- sleep(5);
- fill_screen();
- clrscr();
- }